#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countTriplets(vector<int>& nums) {
        int arr[1 << 16] = { 0 };
        for (int i = 0; i < nums.size(); i++) {
            for (int j = 0; j < nums.size(); j++) {
                arr[nums[i] & nums[j]]++;
            }
        }
        int ans = 0;
        for (auto e : nums) {
            for (int i = 0; i < (1 << 16); i++) {
                if ((e & i) == 0)
                    ans += arr[i];
            }
        }
        return ans;

    }
};